package com.eduhzy.ttw.teacher.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.decoration.DividerItemDecoration;
import com.eduhzy.ttw.commonsdk.entity.DiscoverData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.mvp.contract.DiscoverContract;
import com.eduhzy.ttw.teacher.mvp.model.DiscoverModel;
import com.jess.arms.di.scope.FragmentScope;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-7-20 15:33:28
 */
@Module
public abstract class DiscoverModule {

    @Binds
    abstract DiscoverContract.Model bindDiscoverModel(DiscoverModel model);

    @FragmentScope
    @Provides
    static List<DiscoverData> provideList() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    static BaseQuickAdapter<DiscoverData, AutoBaseViewHolder> provideActivityAdapter(List<DiscoverData> list) {
        return new BaseQuickAdapter<DiscoverData, AutoBaseViewHolder>(R.layout.rv_item_discover, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, DiscoverData item) {
                helper.setText(R.id.tv_title, item.getTitle());
                helper.setText(R.id.tv_name, item.getAuthor());
                helper.setText(R.id.tv_time, TimeUtils.millis2String(item.getSortDate(), new SimpleDateFormat("yyyy-MM-dd")));
                Glide.with(mContext)
                    .load(item.getPreImage())
                    .apply(RequestOptions.placeholderOf(R.drawable.img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                    .into((ImageView) helper.getView(R.id.iv_avatar));
            }

        };

    }


    @FragmentScope
    @Provides
    static DividerItemDecoration provideDividerItemDecoration(DiscoverContract.View view, List<DiscoverData> list) {
        return new DividerItemDecoration(view.getActivity(), DividerItemDecoration.VERTICAL_LIST);
    }

    @FragmentScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger( DiscoverContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }
    
}